package com.hp.item.modular;

import net.minecraft.world.item.Item;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.registries.ObjectHolder;
import se.mickelus.mutil.network.PacketHandler;
import se.mickelus.tetra.data.DataManager;
import se.mickelus.tetra.gui.GuiModuleOffsets;
import se.mickelus.tetra.items.modular.ModularItem;
import se.mickelus.tetra.module.SchematicRegistry;
import se.mickelus.tetra.module.schematic.RemoveSchematic;
import se.mickelus.tetra.module.schematic.RepairSchematic;

import javax.annotation.ParametersAreNonnullByDefault;

@ParametersAreNonnullByDefault
public class Heart extends ModularItem {

    public static final String leftAtriumKey = "left_atrium";
    public static final String rightAtriumKey = "right_atrium";

    public static final String identifier = "heart";

    private static final GuiModuleOffsets majorOffsets = new GuiModuleOffsets(new int[]{-11, 21,1, -3});

    @ObjectHolder(registryName = "item", value = "tetra_organ:heart")
    public static Heart instance;

    public Heart() {
        super(new Item.Properties().stacksTo(1).fireResistant());

        majorModuleKeys = new String[]{leftAtriumKey, rightAtriumKey};
        minorModuleKeys = new String[]{};
        requiredModules = new String[]{leftAtriumKey, rightAtriumKey};

        SchematicRegistry.instance.registerSchematic(new RepairSchematic(this, identifier));
        RemoveSchematic.registerRemoveSchematics(this, identifier);
    }

    @OnlyIn(Dist.CLIENT)
    @Override
    public GuiModuleOffsets getMajorGuiOffsets() {
        return majorOffsets;
    }

    public void commonInit(PacketHandler packetHandler) {
        DataManager.instance.synergyData.onReload(() ->
                this.synergies = DataManager.instance.getSynergyData(identifier + "/")
        );
    }
}
